package com.internal.SharedModule.server;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.internal.Internalhibernate.client.MlLicenses;
import com.internal.Internalhibernate.client.MlQualifications;
import com.internal.Internalhibernate.client.SecUsers;
import com.internal.SharedModule.client.MLLicensesSearchBean;
import com.internal.SharedModule.client.MLQualificationsBean;
import com.internal.SharedModule.client.SecUsersDTO;

public class CloneServerUtil {

	
	public static List<MLLicensesSearchBean> getMLLicensesSearchBean(List<MlLicenses> mlLicenses){
		List<MLLicensesSearchBean> licensesSearchBeans=new ArrayList<MLLicensesSearchBean>();
		
		for (int i = 0; i < mlLicenses.size(); i++) {
			MLLicensesSearchBean licensesSearchBean=new MLLicensesSearchBean();
			
			licensesSearchBean.setAddress(mlLicenses.get(i).getAddress());
			licensesSearchBean.setAddressEn(mlLicenses.get(i).getAddressEn());
			licensesSearchBean.setConfirmedFlag(mlLicenses.get(i).getConfirmedFlag());
			licensesSearchBean.setDateStamp(mlLicenses.get(i).getDateStamp());
			licensesSearchBean.setDecision(mlLicenses.get(i).getDecision());
			licensesSearchBean.setEmail(mlLicenses.get(i).getEmail());
			licensesSearchBean.setGender(mlLicenses.get(i).isGender());
			licensesSearchBean.setImageId(mlLicenses.get(i).getMlImage().getImageId());
			licensesSearchBean.setImageName(mlLicenses.get(i).getMlImage().getImageName());
			licensesSearchBean.setLicenseDate(mlLicenses.get(i).getLicenseDate());
			licensesSearchBean.setLicenseEndDate(mlLicenses.get(i).getLicenseEndDate());
			licensesSearchBean.setLicenseNumber(mlLicenses.get(i).getId().getLicenseNumber());
			licensesSearchBean.setLicenseType(mlLicenses.get(i).isLicenseType());
			licensesSearchBean.setNameA(mlLicenses.get(i).getNameA());
			licensesSearchBean.setNameE(mlLicenses.get(i).getNameE());
			licensesSearchBean.setNatId(mlLicenses.get(i).getAdmNationalities().getNatId());
			licensesSearchBean.setNationalId(mlLicenses.get(i).getNationalId());
			licensesSearchBean.setNationality(mlLicenses.get(i).getAdmNationalities().getNationality());
			licensesSearchBean.setNotes(mlLicenses.get(i).getNotes());
			licensesSearchBean.setPhone(mlLicenses.get(i).getPhone());
			licensesSearchBean.setProfession(mlLicenses.get(i).getAdmProfessions().getProfession());
			licensesSearchBean.setProId(mlLicenses.get(i).getId().getProId());
			licensesSearchBean.setRadiationEffort(mlLicenses.get(i).getRadiationEffort());
			licensesSearchBean.setRadiationType(mlLicenses.get(i).getRadiationType());
			licensesSearchBean.setSerialFlag(mlLicenses.get(i).getId().getSerialFlag());
			licensesSearchBean.setUserId(mlLicenses.get(i).getSecUsersByUserIdI().getUserId());
			
			List<MLQualificationsBean> mlQualificationsBeans=new ArrayList<MLQualificationsBean>();
			Set<MlQualifications> mlQulif = mlLicenses.get(i).getMlQualificationses();
			
			for (MlQualifications mlQualification : mlQulif) {
				MLQualificationsBean mlQualificationsBean=new MLQualificationsBean();
				
				mlQualificationsBean.setDegId(mlQualification.getId().getDegId());
				mlQualificationsBean.setDegree(mlQualification.getAdmSpecialty().getAdmDegree().getDegree());
				mlQualificationsBean.setQuaYear(mlQualification.getQuaYear());
				mlQualificationsBean.setSemester(mlQualification.getSemester());
				mlQualificationsBean.setSpecialty(mlQualification.getAdmSpecialty().getSpecialty());
				mlQualificationsBean.setSpeId(mlQualification.getId().getSpeId());
				mlQualificationsBean.setUniId(mlQualification.getAdmUniversities().getUniId());
				mlQualificationsBean.setUniversity(mlQualification.getAdmUniversities().getUniversity());
				mlQualificationsBeans.add(mlQualificationsBean);
				
			}
			
			licensesSearchBean.setMlQualificationsBeans(mlQualificationsBeans);
			
			licensesSearchBeans.add(licensesSearchBean);
		}
		
		return licensesSearchBeans;
	}

	public static SecUsersDTO cloneSecUser(SecUsers user) {
		SecUsersDTO clonedUsr = new SecUsersDTO();
		clonedUsr.setUserId(user.getUserId());
		clonedUsr.setActiveFlag(user.isActiveFlag());
		clonedUsr.setUserName(user.getUserName());
		clonedUsr.setUserPassword(user.getUserPassword());
		clonedUsr.setSecRoles(user.getSecRoles());
		clonedUsr.setMlLicensesesForUserIdI(user.getMlLicensesesForUserIdI());
		clonedUsr.setMlLicensesesForUserIdU(user.getMlLicensesesForUserIdU());

		return clonedUsr;
	}
}
